﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zor_DAL;
using Zor_Modes;
using Zor_Tools;

namespace Zor_Bll
{
    /// <summary>
    /// 角色管理
    /// create by ternence at 2012.3.22
    /// </summary>
    public class Sys_Roles_Bll<T> where T : class
    {

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="TotalCount">返回值</param>
        /// <returns></returns>
        public static List<T> GetPageList(int index,out int TotalCount)
        {
            return PagerHelp<T>.GetPagerList(index, "Sys_Roles", "Roles_Id", out TotalCount);
        }

        /// <summary>
        /// 角色管理-修改
        /// </summary>
        /// <param name="roles">角色对象</param>
        /// <returns>应答</returns>
        public static BaseAnswer UpdateRoles(Sys_Roles roles)
        {
            BaseAnswer bar = Sys_Roles_DAL<T>.UpdateRoles(roles);
            if(bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "修改成功！" : "修改失败,请检查角色名称是否重复！";
            return bar;
        }

        /// <summary>
        /// 角色管理-新增
        /// </summary>
        /// <param name="roles">角色对象</param>
        /// <returns>执行结果</returns>
        public static BaseAnswer InsertRoles(Sys_Roles roles)
        {
            BaseAnswer bar = Sys_Roles_DAL<T>.InsertRoles(roles);
            if(bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "增加成功！" : "新增失败，请检查角色名是否重复！";
            return bar;
        }


        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id">角色ID集合</param>
        /// <returns></returns>
        public static BaseAnswer DeleteRoles(int[] id)
        {
            BaseAnswer bar = Sys_Roles_DAL<T>.DeleteRoles(id);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "删除成功！" : "删除失败，请重试！";
            return bar;
        }

        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <returns></returns>
        public static List<T> GetMenuList(int rolesId) 
        {
            return Sys_Navigations_DAL<T>.GetNavigationsMenu(rolesId);
        }


        /// <summary>
        /// 分配权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="menuId"></param>
        /// <returns></returns>
        public static BaseAnswer Allocation(string roleId, string[] menuId)
        {
            BaseAnswer bar = Sys_Roles_DAL<T>.Allocation(roleId, menuId);
            if (bar.AnswerType != BaseAnswer.Answers.Error)
                bar.AnswerMeg = bar.AnswerType == BaseAnswer.Answers.Succee ? "权限分配成功！" : "权限分配失败，请重试！";
            return bar;
            
        }

    }
}
